<template>
	<view class="container">
		<view class="swiper">
			<swiper class="swiper" autoplay="true" interval="5000" duration="500" circular="true" :indicator-dots="false" indicator-active-color="#ffffff">
				<swiper-item>
					<view class="swiper-item uni-bg-red"><image src="http://download.qiyedaishu.com/common/haibao.png"></image></view>
				</swiper-item>
			</swiper>
		</view>
		<view class="menu1" v-if="SysList.length==0">
			<view class="nopower">您尚未开通任何系统<br>请联系管理员开通</view>
		</view>
		<view class="menu1" v-if="CaseType==1">
			<view class="square" @click="CaseAudit" style="background-color: #33cc99;">
				<view class="icon"><image src="/static/audit.png"></image></view>
				<view class="name">案件审核</view>
				<view class="dot" v-if="AuditCount>0">{{AuditCount}}</view>
			</view>
			<view class="square" @click="CaseSearch" style="background-color: #e0764f;">
				<view class="icon"><image src="/static/casesearch.png"></image></view>
				<view class="name">案件查询</view>
				<view class="dot" v-if="NoSettleCount>0">{{NoSettleCount}}</view>
			</view>
			<view class="square" @click="UpdatePwd" style="background-color: #029bff;" v-if="!ShowChart">
				<view class="icon"><image src="/static/pwd.png"></image></view>
				<view class="name">修改密码</view>
			</view>
			<view class="square" @click="CountyList" style="background-color: #029bff;" v-if="ShowChart">
				<view class="icon"><image src="/static/xianqu.png"></image></view>
				<view class="name">县区数据</view>
			</view>
			<view class="square" @click="Exit" style="background-color: #8c63ef;">
				<view class="icon"><image src="/static/exit.png"></image></view>
				<view class="name">退出系统</view>
			</view>
		</view>
		<view class="menu2" v-if="CaseType==2">
			<view class="square" style="background-color: #1fbcb5;" @click="ZeGai()">
				<view class="title"><text style="font-size:48rpx;">责</text>改</view>
				<view class="icon"><image src="/static/zegai.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">责</text>改通知书</view>
				<view class="shadow" style="background-color: #c9e8e2;"></view>
			</view>
			
			<view class="square" style="background-color: #1fbcb5;" @click="ZeGaiList">
				<view class="title"><text style="font-size:48rpx;">查</text>询</view>
				<view class="icon"><image src="/static/casesearch1.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">责</text>改查询</view>
				<view class="shadow" style="background-color: #c9e8e2;"></view>
			</view>
			<view class="square" style="background-color: #e44d44;" @click="ChuFa()">
				<view class="title"><text style="font-size:48rpx;">处</text>罚</view>
				<view class="icon"><image src="/static/chufa.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">处</text>罚决定书</view>
				<view class="shadow" style="background-color: #f2d0d1;"></view>
			</view>
			<view class="square" style="background-color: #e44d44;" @click="ChuFaList">
				<view class="title"><text style="font-size:48rpx;">查</text>询</view>
				<view class="icon"><image src="/static/casesearch2.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">处</text>罚查询</view>
				<view class="shadow" style="background-color: #f2d0d1;"></view>
			</view>
			<view class="square" style="background-color: #8dc73f;" @click="UpdatePwd">
				<view class="title"><text style="font-size:48rpx;">密</text>码</view>
				<view class="icon"><image src="/static/pwd.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">修</text>改密码</view>
				<view class="shadow" style="background-color: #ccf09b;"></view>
			</view>
			<view class="square" style="background-color: #a204fd;" @click="Exit">
				<view class="title"><text style="font-size:48rpx;">退</text>出</view>
				<view class="icon"><image src="/static/exit.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">安</text>全退出</view>
				<view class="shadow" style="background-color: #f2ddfe;"></view>
			</view>
		</view>
		<view class="menu2" v-if="CaseType==3">
			<view class="square" style="background-color: #f27b1d;" @click="Parking">
				<view class="title"><text style="font-size:48rpx;">违</text>停</view>
				<view class="icon"><image src="/static/ting.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">违</text>停处理</view>
				<view class="shadow" style="background-color: #f1dcc9;"></view>
			</view>
			
			<view class="square" style="background-color: #0181fe;" @click="ParkList">
				<view class="title"><text style="font-size:48rpx;">查</text>询</view>
				<view class="icon"><image src="/static/casesearch.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">案</text>件查询</view>
				<view class="shadow" style="background-color: #c4dff4;"></view>
			</view>
			<view class="square" style="background-color: #8dc73f;" @click="UpdatePwd">
				<view class="title"><text style="font-size:48rpx;">密</text>码</view>
				<view class="icon"><image src="/static/pwd.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">修</text>改密码</view>
				<view class="shadow" style="background-color: #ccf09b;"></view>
			</view>
			<view class="square" style="background-color: #a204fd;" @click="Exit">
				<view class="title"><text style="font-size:48rpx;">退</text>出</view>
				<view class="icon"><image src="/static/exit.png"></image></view>
				<view class="name"><text style="font-size:42rpx;">安</text>全退出</view>
				<view class="shadow" style="background-color: #f2ddfe;"></view>
			</view>
		</view>
		<view class="meng" @touchmove.stop.prevent="" @touchmove.stop="" @click.stop="" v-if="ShowUpGrade"></view>
		<view class="upgrade" v-if="ShowUpGrade">
			<!-- <view class="title">升级提醒</view> -->
			<view class="tip"><view class="version">版本号：v{{UpGrade.VersionName}}</view><text class="size" space="emsp">大 小：{{UpGrade.AppSize}}</text></view>
			<view class="context" @touchmove.stop.prevent="" @touchmove.stop="" @click.stop="">
				<scroll-view class="box" scroll-y="true" @touchmove.stop.prevent="" @touchmove.stop="" @click.stop="">
				<text v-html="UpGrade.Context"></text>
				</scroll-view>
		    </view>
			<view class="progress" :class="Percent==0?'invisible':''"><progress :percent="Percent" show-info stroke-width="8" activeColor="#03b3d8"/></view>
			<view class="btns"><!-- <view class="close border-r" @click="CloseUpGrade">关闭</view> -->
				<view class="up" @click="UpGrades" :style="UpGradeText=='立刻升级'?'':'background:#bcbcbc;'">{{UpGradeText}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onShareAppMessage: function() {
		    return {
		      title: this.ComName,
		      path: "pages/index/index"//这是一个路径
		    }
		},
		data() {
			return {
				AuditCount:0,
				NoSettleCount:0,
				CaseType:0,
				ShowUpGrade:false,
				ShowChart:false,
				Percent:0,
				UpGrade:{},
				UpGradeText:'立刻升级',
				ComName:'',
				ImgList:[],
				SysList:[0]
			}
		},
		onShow() {
			//#ifdef APP
			this.CheckAppUpGrade();
			//#endif
			this.Init_Home();
			//以下3行旧版处理完后可删除
			this.AuditCount=0;
			this.NoSettleCount=0;
			this.Init_Home2();
		},
		onLoad() {
			uni.setStorageSync("IsLoad", false);
		},
		methods: {
			Init_Home(){
				var data = {};
				var CaseType = uni.getStorageSync("CaseType") || 0;
				data.Act = "Init_Home";
				data.CaseType = CaseType;
				if(!uni.getStorageSync("IsLoad")){this.Util.Loading("请稍候...");} //切换了系统，要重新显示加载
				this.Util.Post(data, json=>{
					this.Util.HideLoading();
					uni.stopPullDownRefresh();
					uni.setStorageSync("IsLoad", true);
					if(json.State){
						this.AuditCount+=json.Data.AuditCount;
						this.NoSettleCount+=json.Data.NoSettleCount;
						this.CaseType=json.Data.CaseType;
						this.SysList=json.Data.SysList;
						this.ComName= json.Data.ComName;
						this.ShowChart = json.Data.ShowChart;
						uni.setStorageSync("CaseType", json.Data.CaseType);
						if(json.Data.SysName!=""){
							uni.setNavigationBarTitle({
								title:this.ComName+'-'+json.Data.SysName
							})
						}
					}
				});
			},
			Init_Home2(){
				var data = {};
				var CaseType = uni.getStorageSync("CaseType") || 0;
				data.Act = "Init_Home";
				data.CaseType = CaseType;
				if(!uni.getStorageSync("IsLoad")){this.Util.Loading("请稍候...");} //切换了系统，要重新显示加载
				this.Util.Post2(data, json=>{
					this.Util.HideLoading();
					uni.stopPullDownRefresh();
					uni.setStorageSync("IsLoad", true);
					if(json.State){
						this.AuditCount+=json.Data.AuditCount;
						this.NoSettleCount+=json.Data.NoSettleCount;
					}
				});
			},
			ScanIdCard(){
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['camera'], //从相册选择
				    success: res=> {
						var ImgList = res.tempFilePaths;
						this.Util.Loading("识别中...");
						this.Util.ScanUpload(ImgList[0],"upload_file_x",json=>{
							this.Util.HideLoading();
							this.Util.Toast("识别成功");
							uni.navigateTo({
								url:'/pages/easy/caseadd?RealName='+json.RealName+'&IDCard='+json.IdCard
							})
						});
				    }
				});
			},
			CaseAudit(){
				uni.navigateTo({
					url:"/pages/case/caseauditlist"
				})
			},
			CauseAction(Index){
				uni.navigateTo({
					url:"cause?Index="+Index
				})
			},
			CaseSearch(){
				uni.navigateTo({
					url:"/pages/case/casesearchlist"
				})
			},
			UpdatePwd(){
				uni.navigateTo({
					url:"/pages/my/updatepwd"
				})
			},
			CountyList(){
				uni.navigateTo({
					url:"/pages/case/countylist"
				})
			},
			ZeGai(){
				uni.navigateTo({
					url:"/pages/easy/zegaiadd?ID=0"
				})
			},
			ChuFa(){
				uni.navigateTo({
					url:"/pages/easy/chufaadd?ID=0"
				})
			},
			ZeGaiList(){
				uni.navigateTo({
					url:"/pages/easy/zegailist"
				})
			},
			ChuFaList(){
				uni.navigateTo({
					url:"/pages/easy/chufalist"
				})
			},
			Parking(){
				uni.navigateTo({
					url:"/pages/park/parkadd?Type=1&ID=0"
				})
			},
			ParkList(){
				uni.navigateTo({
					url:"/pages/park/parklist"
				})
			},
			CaseList(){
				uni.navigateTo({
					url:"/pages/easy/caselist"
				})
			},
			Exit(){
				this.Util.Confirm("您确定要退出系统吗？",item=>{
					uni.setStorageSync("Token","");
					uni.reLaunch({
						url:"/pages/index/login"
					})
				});
				
			},
			CheckAppUpGrade(){
				var data = {};
				data.Act="Update_Client";
				this.Util.Post(data, json=>{
					if(json.State){
						var WgtCode=this.WgtCode;
						plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
							var VersionCode=wgtinfo.versionCode;
							//更新安装包
							if(json.Data.VersionCode>VersionCode){
								this.ShowUpGrade=true;
								this.UpGrade=json.Data;
							}else{
								//更新升级包
								if(json.Data.WgtCode>WgtCode){
									this.Util.DownloadWgt(json.Data.WgtUrl);
								}
							}
						});
						
					}
				});
			},
			UpGrades(){
				if(this.UpGrade.Source==3){
					if(this.UpGradeText=="立刻升级"){
						this.UpGradeText="正在升级";
						this.Util.DownloadApp(this.UpGrade.AppUrl,Percent=>{
							this.Percent=Percent;
						});
					}
				}else{
					//plus.runtime.openURL('http://www.qiyedaishu.com/DownloadApp.html', null, null );
				}
			}
		}
	}
</script>

<style lang="scss">
	.container{padding-left:25rpx; padding-top:25rpx;
		.swiper{width:700rpx; height:300rpx; border-radius: 14rpx;
			swiper-item{width:100%; height:300rpx; border-radius: 14rpx;
				.swiper-item{width:100%; height:300rpx; border-radius: 14rpx;}
			}
			image{width:100%;height:300rpx; border-radius: 10rpx; overflow:hidden;}
		}
		.menu1{width:700rpx; height:auto; padding-left:25rpx; padding-right: 25rpx; display: flex; flex-direction: row; justify-content:space-between;flex-wrap: wrap;
			.nopower{width:100%; height: 300rpx; padding-top:150rpx; line-height: 60rpx; text-align: center; font-size:40rpx; color:#cdcdcd;}
			.square{width:300rpx; height:330rpx; position: relative; padding-left:25rpx; padding-right:25rpx; margin-top:40rpx; padding-top:40rpx; border-radius:40rpx; 
				.icon{width:250rpx; height:180rpx; display:flex; flex-direction: column;  align-items: center; padding-top:40rpx; image{width:100rpx;height: 100rpx;}}
				.name{width:100%; height:50rpx; padding-top:10rpx; text-align: center; font-size:40rpx; color:#ffffff;}
				.dot{width:50rpx; height:50rpx; line-height: 50rpx; text-align: center; background-color: red; color:#ffffff; border-radius:50%; position:absolute; top:-15rpx; right: -15rpx;}
			}
			.square:active{opacity: 0.6; border-radius:40rpx;}
		}
		.menu2{width:700rpx; padding-left:20rpx; padding-right: 20rpx; height:auto; padding-top:50rpx; display: flex; flex-direction: row; justify-content: space-between; flex-wrap: wrap;
			.square{width:315rpx; height:200rpx; padding-left:30rpx; padding-right:30rpx; border-radius: 20rpx; padding-top:30rpx; margin-bottom:30rpx; position: relative; color:#ffffff; display:flex; flex-direction: row; flex-wrap: wrap;
				.title{flex:1; height:60rpx; font-weight: lighter;}
				.icon{width:50rpx; height:50rpx; margin-top:10rpx; image{width:50rpx; height: 50rpx;}}
				.name{width:100%; height:100rpx; padding-top:10rpx; font-size:32rpx;}
				.shadow{width:90%; height:60rpx; border-radius: 20rpx; position: absolute; bottom:-12rpx; left:5%; z-index:-1;}
				
			}
			.square:active{opacity: 0.6;}
			.square:active .shadow{opacity: 0;}
		}
		.meng{width:100vw; height:100vh; background-color: #000000; opacity:0.3; position:fixed; z-index:102; top:0rpx; left:0rpx;}
	}
</style>
